package projectisd.client;

import java.util.List;

import com.google.gwt.core.client.GWT;
import com.google.gwt.user.client.rpc.AsyncCallback;
/** 
 * Dit is de klas die de functies uit Leerling die de functies Async maakt en functies aanmaakt
 * om de array list te updaten, verwijderen en iets aan toe te voegen daaraan.
 * @author Team 2
 * @version 7.0
 */
public class LeerlingDelegate {
    private ProjectServiceAsync projectService = GWT.create(ProjectService.class);
    LeerlingGUI gui;
    
    void listLeerlingen() {
    	projectService.listLeerlingen(new AsyncCallback<List<Leerling>> () {
                    public void onFailure(Throwable caught) {
                        gui.service_eventListLeerlingFailed(caught);
                    }
        
                    public void onSuccess(List<Leerling> result) {
                        gui.service_eventListRetrievedFromService(result);
                        
                    }
        }//end of inner class
        );//end of listVakkens method call.
    }
    
    void addLeerling(final Leerling leerling) {
        projectService.addLeerling(leerling, new AsyncCallback<Void> () {
            public void onFailure(Throwable caught) {
                gui.service_eventAddLeerlingFailed(caught);
            }

            public void onSuccess(Void result) {
                gui.service_eventAddLeerlingSuccessful();
            }
        }//end of inner class
        );//end of addVak method call.        
    }

    void updateLeerling(final Leerling leerling) {
    	projectService.updateLeerling(leerling, new AsyncCallback<Void> () {
            public void onFailure(Throwable caught) {
                gui.service_eventUpdateLeerlingFailed(caught);
            }

            public void onSuccess(Void result) {
                gui.service_eventUpdateSuccessful();
            }
        }//end of inner class
        );//end of updateLeerling method call.        
    }

    void removeLeerling(final Leerling leerling) {
    	projectService.removeLeerling(leerling, new AsyncCallback<Void> () {
            public void onFailure(Throwable caught) {
                gui.service_eventRemoveLeerlingFailed(caught);
            }

            public void onSuccess(Void result) {
                gui.service_eventRemoveLeerlingSuccessful();
            }
        }//end of inner class
        );//end of updateLeerling method call.        
    }
    
}
